<?php
	//	Author: 	Christos Polydorou
	//	Email:		std04237@di.uoa.gr
	//	Purpose: 	Check if a username already exists

	require_once("../DB/connection.php");
	require_once("../DB/defines.php");
	require_once("../Frameworks/Objects/user.php");
	require_once("../Frameworks/Objects/category.php");

	function DB_usernameExists($username){

		global $conn;

		// The name of the stored procedure
		$sp_name = "usp_usernameExists";

		// The return variable
		$retval;

		// Create a new statement
		$stmt = mssql_init($sp_name,$conn);

		// Bind values
		mssql_bind($stmt, "RETVAL",    $retval,  SQLINT4, true, false, 1	);
		mssql_bind($stmt, "@username",    $username, SQLVARCHAR, false, false, 50);

		// Execute the statement
		$status = mssql_execute($stmt);
		if( $status ){
			return $retval;
		}
		else
		{
			return 0;
		}
	}

?>